var KOC = require("koc.common.utils");
var fs = require('fs');
var Config = require("../../config");

var StateData = require("../statedata");
var DALFactory = require("../../lib/dal/dal-factory");
var CommonUtils = require("../../lib/common-utils");
var FileBuilder = require("../../lib/file-builder");
var Interface_QCloud = require("../../lib/interface-qcloud");
var Interface_Geetest = require("../../lib/interface-geetest");

module.exports = {
    Service: function (req, res) {
        var _UserData = StateData.Value(req, res);//取得状态
        switch (req.params.type) {
            //region Base
            case "base.user-photo.avatar":
                ajaxFactory.Base.User_Photo.Avatar(req, res, _UserData);
                return;
            case "base.user-photo.cover":
                ajaxFactory.Base.User_Photo.Cover(req, res, _UserData);
                return;
            case "base.user-anchoridcard":
                ajaxFactory.Base.User_AnchorIDCard(req, res, _UserData);
                return;
            case "base.user-anchoridcardquery"://临时方法
                ajaxFactory.Base.User_AnchorIDCardQuery(req, res);
                return;
            case "base.user-reportimg":
                ajaxFactory.Base.User_ReportImg(req, res, _UserData);
                return;
            case "base.user-eventimg":
                ajaxFactory.Base.User_EventImg(req, res, _UserData);
                return;
            case "base.weekstarconfig":
                ajaxFactory.Base.WeekStarConfig(req, res, _UserData);
                return;
            case "base.lotteryinfo":
                ajaxFactory.Base.LotteryInfo(req, res);
                return;
            //endregion
            //region Business
            case "business.user-passwordupdate":
                ajaxFactory.Business.User_PasswordUpdate(req, res, _UserData);
                return;
            case "business.family-info":
                ajaxFactory.Business.Family_Info(req, res, _UserData);
                return;
            case "business.user-anchorapply.stepone":
                ajaxFactory.Business.User_AnchorApply.StepOne(req, res, _UserData);
                return;
            case "business.user-anchorapply.steptwo":
                ajaxFactory.Business.User_AnchorApply.StepTwo(req, res, _UserData);
                return;
            case "business.user-anchorapply.stepthree":
                ajaxFactory.Business.User_AnchorApply.StepThree(req, res, _UserData);
                return;
            case "business.user-familyapply.stepone":
                ajaxFactory.Business.User_FamilyApply.StepOne(req, res, _UserData);
                return;
            case "business.user-familyapply.steptwo":
                ajaxFactory.Business.User_FamilyApply.StepTwo(req, res, _UserData);
                return;
            case "business.user-report":
                ajaxFactory.Business.User_Report(req, res, _UserData);
                return;
            case "business.user-withdraw":
                ajaxFactory.Business.User_Withdraw(req, res, _UserData);
                return;
            case "business.user-feedbackmessage":
                ajaxFactory.Business.User_FeedBackMessage(req, res, _UserData);
                return;
            case "business.user-emblem":
                ajaxFactory.Business.User_Emblem(req, res, _UserData);
                return;
            case "business.user-weekstar":
                ajaxFactory.Business.User_WeekStar(req, res, _UserData);
                return;
            case "business.user-chanelsignuppayinfo":
                ajaxFactory.Business.User_Channel_SignUp_Pay_Info(req, res, _UserData);
                return;
            //endregion
            //region User
            case "user.user-info.info":
                ajaxFactory.User.User_Info.Info(req, res, _UserData);
                return;
            case "user.user-info.page":
                ajaxFactory.User.User_Info.Page(req, res, _UserData);
                return;
            case "user.user-info.update":
                ajaxFactory.User.User_Info.Update(req, res, _UserData);
                return;
            case "user.user-info.updatephone":
                ajaxFactory.User.User_Info.UpdatePhone(req, res, _UserData);
                return;
            case "user.user-info.updatepassword":
                ajaxFactory.User.User_Info.UpdatePassword(req, res, _UserData);
                return;
            case "user.user-info.checkphone":
                ajaxFactory.User.User_Info.CheckPhone(req, res, _UserData);
                return;
            case "user.user-info.checkbindphone":
                ajaxFactory.User.User_Info.CheckUserBindPhone(req, res, _UserData);
                return;
            case "user.user-info.currencyexchange":
                ajaxFactory.User.User_Info.CurrencyExchange(req, res, _UserData);
                return;
            case "user.user-task.list":
                ajaxFactory.User.User_Task.List(req, res, _UserData);
                return;
            case "user.user-task.update-receive":
                ajaxFactory.User.User_Task.Update_Receive(req, res, _UserData);
                return;
            case "user.user-anchor.update":
                ajaxFactory.User.User_Anchor.Update(req, res, _UserData);
                return;
            case "user.user-anchor.page":
                ajaxFactory.User.User_Anchor.Page(req, res, _UserData);
                return;
            case "user.user-anchor-guardian.list-guardian":
                ajaxFactory.User.User_Anchor_Guardian.List_Guardian(req, res, _UserData);
                return;
            case "user.user-contribution.list":
                ajaxFactory.User.User_Contribution.List(req, res, _UserData);
                return;
            case "user.user-attention.page":
                ajaxFactory.User.User_Attention.Page(req, res, _UserData);
                return;
            case "user.user-attention.anchorfans":
                ajaxFactory.User.User_Attention.AnchorFans(req, res, _UserData);
                return;
            case "user.order-gift.pageuser":
                ajaxFactory.User.Order_Gift.PageUser(req, res, _UserData);
                return;
            case "user.order-gift.pageanchor":
                ajaxFactory.User.Order_Gift.PageAnchor(req, res, _UserData);
                return;
            case "user.order-guardian.page":
                ajaxFactory.User.Order_Guardian.Page(req, res, _UserData);
                return;
            case "user.order-vip.page":
                ajaxFactory.User.Order_Vip.Page(req, res, _UserData);
                return;
            case "user.order-mounts.page":
                ajaxFactory.User.Order_Mounts.Page(req, res, _UserData);
                return;
            case "user.order-live.pageuser":
                ajaxFactory.User.Order_Live.PageUser(req, res, _UserData);
                return;
            case "user.order-live.pagefamily":
                ajaxFactory.User.Order_Live.PageFamily(req, res, _UserData);
                return;
            case "user.order-pay.page":
                ajaxFactory.User.Order_Pay.Page(req, res, _UserData);
                return;
            case "user.order-withdraw.page":
                ajaxFactory.User.Order_Withdraw.Page(req, res, _UserData);
                return;
            case "user.order-lottery.page":
                ajaxFactory.User.Order_Lottery.Page(req, res, _UserData);
                return;
            case "user.order-lottery.lotteryrank":
                ajaxFactory.User.Order_Lottery.LotteryRank(req, res, _UserData);
                return;
            //endregion
        }
        res.jsonp({flag: -9999, msg: "未知的请求"});
    }
};

var ajaxFactory = {
    Base: {
        //region User_Photo:用户头像
        User_Photo: {
            Avatar: function (req, res, _UserData) {
                //判断权限
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                var parm = {
                    FileName: KOC.StringUtils.ToString(req.params.FileName),
                    FileInfo: []
                };
                parm.FileInfo = parm.FileName.split(".");
                if (parm.FileInfo.length !== 2) {
                    res.jsonp({flag: 1, msg: "请上传图片"});
                    return;
                }
                KOC.Async.series([
                    //上传头像
                    function (callback) {
                        FileBuilder.User.Avatar.Build(_UserData.User_ID, FileBuilder.Common.TempFilePath(parm.FileInfo[0]), function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    },
                    //刷新cdn 头像dir
                    function (callback) {
                        Interface_QCloud.RefreshUrl(FileBuilder.User.Avatar.UrlAll(_UserData.User_ID), function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        })
                    }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "上传完成"});
                });
            },
            Cover: function (req, res, _UserData) {
                //判断权限
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                var parm = {
                    FileName: KOC.StringUtils.ToString(req.params.FileName),
                    FileInfo: []
                };
                parm.FileInfo = parm.FileName.split(".");
                if (parm.FileInfo.length !== 2) {
                    res.jsonp({flag: 1, msg: "请上传图片"});
                    return;
                }
                KOC.Async.series([
                    //上传艺人封面
                    function (callback) {
                        FileBuilder.User.Cover.Build(_UserData.User_ID, FileBuilder.Common.TempFilePath(parm.FileInfo[0]), function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    },
                    //刷新cdn 艺人封面dir
                    // function (callback) {
                    //     Interface_QCloud.RefreshDir(FileBuilder.User.Url(_UserData.User_ID, "cover"), function (retValue) {
                    //         if (retValue.hasError) {
                    //             callback(retValue);
                    //             return;
                    //         }
                    //         callback();
                    //     })
                    // }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "上传完成"});
                });
            }
        },
        //endregion
        //region User_AnchorIDCard:艺人身份证图片上传
        User_AnchorIDCard: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            var parm = {
                FileName: KOC.StringUtils.ToString(req.params.FileName),
                FileInfo: [],
                Front: KOC.StringUtils.ToString(req.params.Front)
            };
            parm.FileInfo = parm.FileName.split(".");
            if (parm.FileInfo.length !== 2) {
                res.jsonp({flag: 1, msg: "请上传图片"});
                return;
            }
            KOC.Async.series([
                function (callback) {
                    DALFactory.User.User_Anchor.Info(_UserData.User_ID, function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        if (retValue.returnObject && retValue.returnObject.Status != 3 && retValue.returnObject.Status != 0) {
                            callback(KOC.ReturnValue.New({
                                hasError: true,
                                errorCode: 2,
                                message: "艺人信息已锁定或正在审批中不能上传身份证图片"
                            }));
                            return;
                        }
                        callback();
                    });
                },
                function (callback) {
                    FileBuilder.User.IDCard.Build(_UserData.User_ID, parm.Front, FileBuilder.Common.TempFilePath(parm.FileInfo[0]), function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        callback();
                    });
                },
                //刷新cdn 艺人封面dir
                function (callback) {
                    Interface_QCloud.RefreshUrl(FileBuilder.User.IDCard.UrlAll(_UserData.User_ID, "idcard-" + parm.Front), function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        callback();
                    })
                }
            ], function (retValue) {
                if (retValue) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                res.jsonp({flag: 0, msg: "上传身份证图片完成"});
            });
        },
        //endregion
        //region User_ReportImg:用户上传举报截图
        User_ReportImg: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            var parm = {
                FileName: KOC.StringUtils.ToString(req.params.FileName),
                FileInfo: []
            };
            parm.FileInfo = parm.FileName.split(".");
            if (parm.FileInfo.length !== 2) {
                res.jsonp({flag: 1, msg: "请上传图片"});
                return;
            }
            FileBuilder.UserReport.Report.Build(_UserData.User_ID, FileBuilder.Common.TempFilePath(parm.FileInfo[0]), function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                res.jsonp({flag: 0, msg: "上传图片完成", path: retValue.returnObject});
            });

        },
        //endregion
        //region User_AnchorIDCardQuery:艺人身份证图片查询是否存在 临时方法
        User_AnchorIDCardQuery: function (req, res, _UserData) {
            DALFactory.User.User_Anchor.Info_All(function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: 1, msg: "读取艺人数据配置失败"});
                    return;
                }
                var _AnchorID_All = '';
                KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                    if (!fs.existsSync(FileBuilder.User.Path(ThisValue.User_ID) + "idcard-a.jpg")) {
                        _AnchorID_All = _AnchorID_All + ThisValue.User_ID + ",";
                    }
                });
                fs.writeFile(Config.Common.Physical_Path.File_Common + 'anchorID.txt', _AnchorID_All, function (error) {
                    if (error) {
                        console.log('失败');
                    }
                    console.log('保存成功');
                });
                console.log('Anchor_NOT_IDCard-------->', _AnchorID_All);
            });
        },
        //endregion
        //region User_EventImg:用户上传勇者大冲关报名的上生活照
        User_EventImg: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            var _FileName = KOC.StringUtils.ToString(req.params.FileName);
            var _FileInfo = _FileName.split(".");
            if (_FileInfo.length !== 2) {
                res.jsonp({flag: 1, msg: "请上传图片"});
                return;
            }
            FileBuilder.UserEvent.Event.Build(_UserData.User_ID, FileBuilder.Common.TempFilePath(_FileInfo[0]), function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                res.jsonp({flag: 0, msg: "上传图片完成", path: retValue.returnObject});
            });
        },
        //endregion
        //region WeekStarConfig:周星数据配置
        WeekStarConfig: function (req, res, _UserData) {
            var GiftList = CommonUtils.Commodity.Gift.Data;
            var WeekStart_GiftList = [];
            for (var index in GiftList) {
                if (GiftList[index].IsWeekStar && GiftList[index].Status == 0) {
                    WeekStart_GiftList.push(GiftList[index].id);
                }
            }
            res.jsonp({flag: 0, msg: "读取周星数据配置完成", data: WeekStart_GiftList});
        },
        //endregion
        //region LotteryInfo:抽奖数据配置
        LotteryInfo: function (req, res) {
            var Category = null;
            if (req.params && req.params.Type && KOC.StringUtils.ToInt(req.params.Type, -1) > 0) {
                Category = KOC.StringUtils.ToInt(req.params.Type);
            }
            DALFactory.User.Lottery_Info.Info_CategoryAll({
                Category: Category
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: 1, msg: "读取抽奖数据配置失败"});
                    return;
                }
                //数据处理
                var data = {
                    key1: [],
                    key2: [],
                    key3: [],
                    key4: []
                };
                for (var key in retValue.returnObject) {
                    switch (retValue.returnObject[key].Category) {
                        case 1:
                            data.key1.push(retValue.returnObject[key]);
                            break;
                        case 2:
                            data.key2.push(retValue.returnObject[key]);
                            break;
                        case 3:
                            data.key3.push(retValue.returnObject[key]);
                            break;
                        case 4:
                            data.key4.push(retValue.returnObject[key]);
                            break;
                        default:
                            break;
                    }
                }
                res.jsonp({flag: 0, msg: "读取抽奖数据配置完成", data: data});
            });
        }
        //endregion
    },
    Business: {
        //region User_PasswordUpdate:修改密码
        User_PasswordUpdate: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            if (!req.params.Password || req.params.Password == "") {
                res.jsonp({flag: 1, msg: "新密码错误，请重新输入密码"});
                return;
            }
            if (!req.params.Password_Old || req.params.Password_Old == "") {
                res.jsonp({flag: 1, msg: "旧密码错误，请重新输入密码"});
                return;
            }
            if (req.params.Password_Old == req.params.Password) {
                res.jsonp({flag: 1, msg: "新密码不能和旧密码相同"});
                return;
            }
            DALFactory.Business.User_PasswordUpdate({
                User_ID: _UserData.User_ID,
                Password: req.params.Password,
                Password_Old: req.params.Password_Old,
                Phone: null,
                Type: true //修改密码类型，true-验证旧密码,传User_ID，false-不验证旧密码,传Phone
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                res.jsonp({flag: 0, msg: "密码修改完成"});
            });
        },
        //endregion
        //region Family_Info:查看公会信息
        Family_Info: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            if (!req.params.Family_ID) {
                res.jsonp({flag: 7, msg: "请输入公会ID"});
                return;
            }
            DALFactory.User.Family_Info.Info(req.params.Family_ID, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                if (!retValue.returnObject) {
                    res.jsonp({flag: -2, msg: "没有相应的公会，请重新输入"});
                    return;
                }
                res.jsonp({
                    flag: 0,
                    msg: "",
                    Family_ID: retValue.returnObject.Family_ID,
                    Family_Name: retValue.returnObject.Family_Name
                });
            });
        },
        //endregion
        //region User_AnchorApply:用户艺人申请
        User_AnchorApply: {
            StepOne: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                var _PageData = {
                    flag: 0,
                    msg: ""
                };
                if (!req.params.Phone) {
                    res.jsonp({flag: 2, msg: "请输入手机号"});
                    return;
                }
                if (!(/^0?(13[0-9]|15[012356789]|18[0123456789]|17[0123456789]|14[57])[0-9]{8}$|^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/).test(req.params.Phone)) {
                    res.jsonp({flag: 3, msg: "你输入的手机号格式不正确"});
                    return;
                }
                if (!req.params.Email) {
                    res.jsonp({flag: 4, msg: "请输入email"});
                    return;
                }
                if (!(/^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/).test(req.params.Email)) {
                    res.jsonp({flag: 5, msg: "你输入的email格式不正确"});
                    return;
                }
                if (!req.params.RealName) {
                    res.jsonp({flag: 6, msg: "请输入真实姓名"});
                    return;
                }
                if (!req.params.QQ) {
                    res.jsonp({flag: 7, msg: "请输入QQ号"});
                    return;
                }
                KOC.Async.series([
                    function (callback) {
                        if (!req.params.Family_ID) {
                            callback();
                            return;
                        }
                        DALFactory.User.Family_Info.Info(req.params.Family_ID, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            if (!retValue.returnObject) {
                                retValue.errorCode = -2;
                                retValue.message = "没有相应的公会，请重新输入";
                                callback(retValue);
                                return;
                            }
                            _PageData.Family_ID = retValue.returnObject.Family_ID;
                            _PageData.Family_Name = retValue.returnObject.Family_Name;
                            callback();
                        });
                    },
                    function (callback) {
                        DALFactory.RedisCommon.UserAnchorApply.StepOne({
                            User_ID: _UserData.User_ID,
                            Sex: req.params.Sex,
                            RealName: req.params.RealName,
                            Phone: req.params.Phone,
                            QQ: req.params.QQ,
                            Email: req.params.Email,
                            Tags: req.params.Tags,
                            Network: req.params.Network,
                            Family_ID: req.params.Family_ID
                        }, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    }], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({
                        flag: 0,
                        msg: "验证成功",
                        Family_ID: _PageData.Family_ID,
                        Family_Name: _PageData.Family_Name
                    });
                });
            },
            StepTwo: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                if (!req.params.Account_RealName) {
                    res.jsonp({flag: 1, msg: "请输入开户行姓名"});
                    return;
                }
                if (!req.params.Account_CardNo) {
                    res.jsonp({flag: 2, msg: "请输入开户行账号"});
                    return;
                }
                if (!req.params.Account_BankFullName) {
                    res.jsonp({flag: 3, msg: "请选择开户行"});
                    return;
                }
                if (!req.params.Account_Province) {
                    res.jsonp({flag: 4, msg: "请选择省份"});
                    return;
                }
                if (!req.params.Account_City) {
                    res.jsonp({flag: 5, msg: "请选择市"});
                    return;
                }
                if (!req.params.Account_BankName) {
                    res.jsonp({flag: 6, msg: "请输入开户行地址及分行名称"});
                    return;
                }
                if (!req.params.IDCard) {
                    res.jsonp({flag: 7, msg: "请输入身份证号"});
                    return;
                }
                if (!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(req.params.IDCard))) {
                    res.jsonp({flag: 7, msg: "身份证格式不正确"});
                    return;
                }
                KOC.Async.series([
                    //验证身份证
                    function (callback) {
                        DALFactory.User.User_Anchor.Info_IDCard(req.params.IDCard, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            if (retValue.returnObject) {
                                retValue.errorCode = 1;
                                retValue.message = '身份证号重复，请重新填写';
                                callback(retValue);
                                return;
                            }
                            callback();
                        })
                    },
                    //写入redis
                    function (callback) {
                        DALFactory.RedisCommon.UserAnchorApply.StepTwo({
                            User_ID: _UserData.User_ID,
                            Account_RealName: req.params.Account_RealName,
                            Account_CardNo: req.params.Account_CardNo,
                            Account_BankFullName: req.params.Account_BankFullName,
                            Account_Province: req.params.Account_Province,
                            Account_City: req.params.Account_City,
                            Account_BankName: req.params.Account_BankName,
                            IDCard: req.params.IDCard
                        }, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: ""});
                });
            },
            StepThree: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                DALFactory.Business.User_AnchorApply({
                    User_ID: _UserData.User_ID,
                    Create_IP: KOC.StringUtils.GetClientIP(req)
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "申请完成,请等待管理员审核"});
                })
            }
        },
        //endregion
        //region User_FamilyApply:用户公会申请
        User_FamilyApply: {
            StepOne: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                if (!req.params.Phone) {
                    res.jsonp({flag: 1, msg: "请输入手机号"});
                    return;
                }
                if (!req.params.Family_Name) {
                    res.jsonp({flag: 1, msg: "请输入公会名称"});
                    return;
                }
                if (!(/^0?(13[0-9]|15[012356789]|18[0123456789]|17[0123456789]|14[57])[0-9]{8}$|^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/).test(req.params.Phone)) {
                    res.jsonp({flag: 2, msg: "你输入的手机号格式不正确"});
                    return;
                }
                if (!req.params.Email) {
                    res.jsonp({flag: 3, msg: "请输入email"});
                    return;
                }
                if (!(/^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/).test(req.params.Email)) {
                    res.jsonp({flag: 4, msg: "你输入的email格式不正确"});
                    return;
                }
                if (!req.params.ContactName) {
                    res.jsonp({flag: 5, msg: "请输入真实姓名"});
                    return;
                }
                if (!req.params.QQ) {
                    res.jsonp({flag: 6, msg: "请输入QQ号"});
                    return;
                }
                DALFactory.RedisCommon.UserFamilyApply.StepOne({
                    User_ID: _UserData.User_ID,
                    ContactName: req.params.ContactName,
                    Family_Name: req.params.Family_Name,
                    Phone: req.params.Phone,
                    QQ: req.params.QQ,
                    Email: req.params.Email
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: ""});
                });
            },
            StepTwo: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                if (!req.params.Account_RealName) {
                    res.jsonp({flag: 1, msg: "请输入开户行姓名"});
                    return;
                }
                if (!req.params.Account_CardNo) {
                    res.jsonp({flag: 2, msg: "请输入开户行账号"});
                    return;
                }
                if (!req.params.Account_BankFullName) {
                    res.jsonp({flag: 3, msg: "请选择开户行"});
                    return;
                }
                if (!req.params.Account_Province) {
                    res.jsonp({flag: 4, msg: "请选择省份"});
                    return;
                }
                if (!req.params.Account_City) {
                    res.jsonp({flag: 5, msg: "请选择市"});
                    return;
                }
                if (!req.params.Account_BankName) {
                    res.jsonp({flag: 6, msg: "请输入开户行地址及分行名称"});
                    return;
                }
                if (!req.params.IDCard) {
                    res.jsonp({flag: 7, msg: "请输入身份证号"});
                    return;
                }
                if (!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(req.params.IDCard))) {
                    res.jsonp({flag: 7, msg: "身份证格式不正确"});
                    return;
                }
                KOC.Async.series([
                    //验证身份证
                    function (callback) {
                        DALFactory.User.Family_Info.Info_IDCard(req.params.IDCard, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            if (retValue.returnObject) {
                                retValue.errorCode = 1;
                                retValue.message = '身份证号重复，请重新填写';
                                callback(retValue);
                                return;
                            }
                            callback();
                        })
                    },
                    function (callback) {
                        DALFactory.RedisCommon.UserFamilyApply.StepTwo({
                            User_ID: _UserData.User_ID,
                            Account_RealName: req.params.Account_RealName,
                            Account_CardNo: req.params.Account_CardNo,
                            Account_BankFullName: req.params.Account_BankFullName,
                            Account_Province: req.params.Account_Province,
                            Account_City: req.params.Account_City,
                            Account_BankName: req.params.Account_BankName,
                            IDCard: req.params.IDCard
                        }, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    },
                    function (callback) {
                        DALFactory.Business.User_FamilyApply({
                            User_ID: _UserData.User_ID,
                            Create_IP: KOC.StringUtils.GetClientIP(req)
                        }, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: ""});
                });
            }
        },
        //endregion
        //region User_Report:用户举报
        User_Report: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            DALFactory.User.User_Report.Insert({
                User_ID: _UserData.User_ID,
                Content: req.params.Content ? req.params.Content : "",
                Screenshot: req.params.Screenshot,
                Type: req.params.Type,
                Anchor_ID: req.params.Anchor_ID,
                Create_IP: KOC.StringUtils.GetClientIP(req)
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                //返回
                res.jsonp({flag: 0, msg: "举报成功"});
            });
        },
        //endregion
        //region User_Withdraw:用户申请提现
        User_Withdraw: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            DALFactory.Business.User_AnchorWithdraw({
                User_ID: _UserData.User_ID,//艺人ID
                Coin: req.params.Coin ? KOC.StringUtils.ToInt(req.params.Coin) : 0,//兑换的金豆数
                Create_IP: KOC.StringUtils.GetClientIP(req)
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                //返回
                res.jsonp({flag: 0, msg: "用户申请成功"});
            });
        },
        //endregion
        //region User_WeekStar:周星榜
        User_WeekStar: function (req, res, _UserData) {
            var _Value = {
                Gift_ID: req.params.Gift_ID,
                Length: req.params.Length ? req.params.Length : 20,
                Type: req.params.Type,
                Week: req.params.Week,
                StartTime: req.params.StartTime,
                EndTime: req.params.EndTime
            };
            KOC.Async.series([
                //老版本单个榜单请求
                function (callback) {
                    if (!_Value.Gift_ID || _Value.Gift_ID <= 0 || _Value.Gift_ID == undefined) {
                        callback();
                        return;
                    }
                    DALFactory.Business.User_WeekStarRank({
                        Gift_ID: _Value.Gift_ID,//礼物ID
                        Length: _Value.Length,//请求个数
                        Type: _Value.Type,//请求类型：1-艺人周星榜，2-粉丝周星榜
                        Week: _Value.Week, //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
                        StartTime: _Value.StartTime,
                        EndTime: _Value.EndTime
                    }, function (retValue) {
                        if (retValue.hasError) {
                            res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                            return;
                        }
                        _Value.data = retValue.returnObject;
                        //返回
                        callback();
                    });
                },
                //获取周星榜列表
                function (callback) {
                    if (_Value.Gift_ID && _Value.Gift_ID > 0) {
                        callback();
                        return;
                    }
                    DALFactory.Business.User_WeekStarRankAll({
                        Week: _Value.Week, //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
                        Length: _Value.Length //请求个数
                    }, function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        _Value.data = retValue.returnObject;
                        callback();
                    });
                }
            ], function (retValue) {
                if (retValue) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }

                res.jsonp({flag: 0, msg: "获取周星榜列表成功", data: _Value.data});
            });
        },
        //endregion
        //region User_FeedBackMessage:用户意见反馈
        User_FeedBackMessage: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            var parm = KOC.Lodash.extend({
                QQ: null,
                Message: null
            }, req.params);
            DALFactory.Business.User_FeedBack({
                User_ID: _UserData.User_ID,
                Type: 1,
                QQ: parm.QQ,
                Message: parm.Message,
                Create_IP: KOC.StringUtils.GetClientIP(req)
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                //返回
                res.jsonp({flag: 0, msg: "意见反馈成功"});
            });
        },
        //endregion
        //region User_Emblem:用户徽章列表
        User_Emblem: function (req, res, _UserData) {
            if (!_UserData.IsLogin) {
                res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                return;
            }
            DALFactory.User.User_Emblem.List(_UserData.User_ID, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                    return;
                }
                //返回
                res.jsonp({flag: 0, msg: "用户徽章列表成功", data: retValue.returnObject});
            });
        },
        //endregion
        //region User_Channel_SignUp_Pay_Info：渠道注册充值信息数据
        User_Channel_SignUp_Pay_Info: function (req, res, _UserData) {
            if (!req.params.Create_Date_Between || !req.params.Create_Date_And) {
                req.params.Create_Date_Between = new Date();
                req.params.Create_Date_And = new Date();
            }
            DALFactory.Business.User_Channel_SignUp_Pay_Info({
                Channel_ID: req.params.Channel_ID,//渠道ID
                Create_Date_Between: req.params.Create_Date_Between,
                Create_Date_And: req.params.Create_Date_And
            }, function (retValue) {
                if (retValue.hasError) {
                    res.jsonp({flag: 1, msg: retValue.message});
                    return;
                }
                //返回
                res.jsonp({flag: 0, msg: "获取渠道注册充值信息数据成功", data: retValue.returnObject});
            });
        }
        //endregion
    },
    User: {
        //region User_Info
        User_Info: {
            Info: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "用户未登录"});
                    return;
                }
                var _parm = {};
                KOC.Async.series([
                    //查询用户信息
                    function (callback) {
                        DALFactory.User.User_Info.Info(_UserData.User_ID, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            if (!retValue.returnObject) {
                                retValue.errorCode = -2;
                                retValue.message = '未找到用户信息'
                                callback(retValue);
                                return;
                            }
                            _parm.EXP = retValue.returnObject.EXP;
                            _parm.Coin = retValue.returnObject.Coin;
                            _parm.Beans = retValue.returnObject.Beans;
                            _parm.Level = retValue.returnObject.Level;
                            _parm.Level_Name = retValue.returnObject.Level_Name;
                            _parm.Level_Next = retValue.returnObject.Level_Next;
                            _parm.Level_Next_Name = retValue.returnObject.Level_Next_Name;
                            _parm.EXP_Next = retValue.returnObject.EXP_Next;
                            _parm.EXP_Difference = retValue.returnObject.EXP_Difference;
                            callback();
                        });
                    },
                    //查询艺人基本信息
                    function (callback) {
                        if (!_UserData.IsAnchor) {
                            callback();
                            return;
                        }
                        DALFactory.User.User_Anchor.Info(_UserData.User_ID, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            if (!retValue.returnObject) {
                                retValue.errorCode = -3;
                                retValue.message = '未找到艺人信息'
                                callback(retValue);
                                return;
                            }
                            _parm.Anchor_EXP = retValue.returnObject.Anchor_EXP;
                            _parm.Anchor_Level = retValue.returnObject.Level;
                            _parm.Anchor_Level_Name = retValue.returnObject.Level_Name;
                            _parm.Anchor_Level_Next = retValue.returnObject.Level_Next;
                            _parm.Anchor_Level_Next_Name = retValue.returnObject.Level_Next_Name;
                            _parm.Anchor_EXP_Next = retValue.returnObject.EXP_Next;
                            _parm.Anchor_EXP_Difference = retValue.returnObject.EXP_Difference;
                            _parm.Anchor_Rating = retValue.returnObject.Rating;
                            callback();
                        });
                    }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    //返回
                    res.jsonp({flag: 0, msg: "", data: _parm});
                });
            },
            Update: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                if (!req.params.Sex) {
                    req.params.Sex = 2;
                }
                KOC.Async.series([
                    //验证用户昵称
                    function (callback) {
                        CommonUtils.User.NickName.fnBuildVerify(req.params.NickName, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            req.params.NickName = retValue.returnObject;
                            callback();
                        });
                    },
                    //修改用户信息
                    function (callback) {
                        DALFactory.User.User_Info.Update({
                            NickName: req.params.NickName,
                            QQ: req.params.QQ,
                            Sex: req.params.Sex,
                            Birthday: req.params.Birthday,
                            Constellation: req.params.Constellation,
                            User_ID: _UserData.User_ID
                        }, function (retValue) {
                            if (retValue.hasError) {
                                retValue.message = "修改用户信息出错,该昵称已被占用";
                                callback(retValue);
                                return;
                            }
                            if (retValue.returnObject !== 1) {
                                retValue.hasError = true;
                                retValue.message = "修改用户信息出错，影响行(" + retValue.returnObject + ")";
                                callback(retValue);
                                return;
                            }
                            callback();
                        });
                    },
                    //提交任务
                    function (callback) {
                        if (req.params.NickName && req.params.NickName != "") {
                            DALFactory.Business.User_Task({
                                User_ID: _UserData.User_ID,
                                User_NickName: req.params.NickName,
                                User_RealName: "",
                                Task_ID: 1001,
                                Task_Progress: 1,
                                Create_IP: KOC.StringUtils.GetClientIP(req)
                            }, function (retValue) {
                                if (retValue.hasError) {
                                    callback(retValue);
                                    return;
                                }
                                callback();
                            });
                        } else {
                            callback();
                        }
                    },
                    //读取用户状态数据
                    function (callback) {
                        DALFactory.Business.User_StateData(res.locals.Data.User_ID, function (retValue) {
                            if (retValue.hasError) {
                                callback(retValue);
                                return;
                            }
                            retValue.returnObject.IsLogin = true;
                            StateData.Set(req, res, retValue.returnObject);
                            callback();
                        });
                    }
                ], function (retValue) {
                    if (retValue) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: ""});
                });
            },
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                //查询参数
                var reqParm = new DALFactory.User.Page.UserInfo_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Phone":
                            reqParm.Phone = reqModel.Filter_Value;
                            break;
                        case "Email":
                            reqParm.Email = reqModel.Filter_Value;
                            break;
                        case "NickName":
                            reqParm.NickName = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.Sex = KOC.StringUtils.ToInt(req.params.Sex);
                reqParm.IsAnchor = KOC.StringUtils.ToInt(req.params.IsAnchor, -1);
                reqParm.IsFamily = KOC.StringUtils.ToInt(req.params.IsFamily, -1);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID, -1);
                reqParm.Status = req.params.F_Status || reqParm.Status;
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "EXP":
                    case "VIP":
                    case "VIP_Expire":
                    case "Coin":
                    case "Coin_Today":
                    case "Coin_Week":
                    case "Coin_Month":
                    case "Coin_Year":
                    case "Coin_Total":
                    case "Fans":
                    case "Attention":
                    case "Login_Count":
                    case "Login_This_Date":
                        break;
                    case "Family_ID":
                        break;
                    default:
                        reqModel.Sort_Col = "`User_ID`";
                        break;
                }
                DALFactory.User.Page.UserInfo(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            QQ: ThisValue.QQ,
                            Sex: ThisValue.Sex,
                            Birthday: ThisValue.Birthday,
                            Constellation: ThisValue.Constellation,
                            EXP: ThisValue.EXP,
                            Level: CommonUtils.User.Level.fnLevel(ThisValue.EXP),
                            VIP: ThisValue.VIP && (!ThisValue.VIP_Expire || KOC.Moment().isBefore(retValue.returnObject.VIP_Expire)),
                            VIP_Expire: ThisValue.VIP_Expire,
                            Coin_Today: ThisValue.Coin_Today,
                            Coin_Week: ThisValue.Coin_Week,
                            Coin_Month: ThisValue.Coin_Month,
                            Coin_Year: ThisValue.Coin_Year,
                            Coin_Total: ThisValue.Coin_Total,
                            Beans: ThisValue.Beans,
                            Beans_Today: ThisValue.Beans_Today,
                            Beans_Week: ThisValue.Beans_Week,
                            Beans_Month: ThisValue.Beans_Month,
                            Beans_Year: ThisValue.Beans_Year,
                            Beans_Total: ThisValue.Beans_Total,
                            Fans: ThisValue.Fans,
                            Attention: ThisValue.Attention,
                            IsAnchor: ThisValue.IsAnchor,
                            IsFamily: ThisValue.IsFamily,
                            Login_Count: ThisValue.Login_Count,
                            Login_This_Date: ThisValue.Login_This_Date,
                            Create_Date: ThisValue.Create_Date,
                            RoomName: ThisValue.RoomName,
                            RoomWelcome: ThisValue.RoomWelcome,
                            Tags: ThisValue.Tags,
                            Live: ThisValue.Live,
                            Live_StartTime: ThisValue.Live_StartTime,
                            Live_Order_No: ThisValue.Live_Order_No,
                            Live_Duration_Total: ThisValue.Live_Duration_Total,
                            Anchor_Pomelo: ThisValue.Anchor_Pomelo,
                            Anchor_Pomelo_Today: ThisValue.Anchor_Pomelo_Today,
                            Anchor_Pomelo_Week: ThisValue.Anchor_Pomelo_Week,
                            Anchor_Pomelo_Month: ThisValue.Anchor_Pomelo_Month,
                            Anchor_Pomelo_Year: ThisValue.Anchor_Pomelo_Year,
                            Anchor_EXP: ThisValue.Anchor_EXP,
                            Anchor_Level: CommonUtils.Anchor.Level.fnLevel(ThisValue.Anchor_EXP).Level,
                            Anchor_Create_Date: ThisValue.Anchor_Create_Date,
                            Anchor_Status: ThisValue.Anchor_Status,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Family_Create_Date: ThisValue.Family_Create_Date,
                            Live_Coin: ThisValue.Live_Coin,
                            Gift_Num: ThisValue.Gift_Num,
                            Gift_Num_Anchor: ThisValue.Gift_Num_Anchor,
                            Gift_Num_User: ThisValue.Gift_Num_User,
                            Gift_Count: ThisValue.Gift_Count,
                            Gift_Count_Anchor: ThisValue.Gift_Count_Anchor,
                            Gift_Count_User: ThisValue.Gift_Count_User,
                            Gift_Coin: ThisValue.Gift_Coin,
                            Gift_Coin_Anchor: ThisValue.Gift_Coin_Anchor,
                            Gift_Coin_User: ThisValue.Gift_Coin_User,
                            Gift_Pond_Count: ThisValue.Gift_Pond_Count,
                            Gift_Pond_Coin: ThisValue.Gift_Pond_Coin,
                            Guardian_Count: ThisValue.Guardian_Count,
                            Guardian_Coin: ThisValue.Guardian_Coin,
                            Live_Pomelo: ThisValue.Live_Pomelo,
                            Live_Duration: ThisValue.Live_Duration,
                            Live_Create_Date: ThisValue.Live_Create_Date,
                            Live_Status: ThisValue.Live_Status
                        });
                    });
                    res.jsonp(PageData);
                });
            },
            //region UpdatePhone 绑定手机功能
            UpdatePhone: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "请登录后进行此操作"});
                    return;
                }
                var parm = KOC.Lodash.extend({
                    Type: null,//绑定手机用户登录的类型1-第三方登录（无密码，设置密码），2-平带账号登录（有密码）
                    Phone: null,
                    Password: null,//用户设置的密码，type=1时传入这个字段
                    VerifyCode: null//手机验证码
                }, req.params);
                parm.User_ID = _UserData.User_ID;
                parm.Type = KOC.StringUtils.ToInt(parm.Type, -1);
                if (parm.Type == 1 && !parm.Password) {
                    res.jsonp({flag: 1, msg: "请输入密码"});
                    return;
                }
                DALFactory.Business.User_OAuthPhone({
                    User_ID: parm.User_ID,
                    OAuth_Phone: parm.Phone,
                    PhoneCode: parm.VerifyCode,
                    Password: parm.Password || null,
                    Create_IP: KOC.StringUtils.GetClientIP(req)
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "绑定手机成功"});
                });
            },
            //endregion
            //region CheckPhone  验证用户手机绑定（验证码）（忘记密码第一步）
            CheckPhone: function (req, res, _UserData) {
                if (_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "登录不能进行此操作"});
                    return;
                }
                var parm = KOC.Lodash.extend({
                    Phone: null,
                    VerifyCode: null//手机验证码
                }, req.params);
                if (!parm.Phone || parm.Phone == "" || parm.Phone <= 0) {
                    res.jsonp({flag: 1, msg: "手机号码错误，请输入正确的手机号码"});
                    return;
                }
                if (!parm.VerifyCode || parm.VerifyCode == "" || parm.VerifyCode <= 0) {
                    res.jsonp({flag: 1, msg: "验证码错误，请输入正确的验证码"});
                    return;
                }
                DALFactory.Business.User_CheckPhone({
                    Phone: parm.Phone,
                    PhoneCode: parm.VerifyCode
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "验证成功"});
                });
            },
            //endregion
            //region UpdatePassword  修改密码（无旧密码）（忘记密码第二步）
            UpdatePassword: function (req, res, _UserData) {
                if (_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "登录无法进行此操作"});
                    return;
                }
                var parm = KOC.Lodash.extend({
                    Phone: null,
                    Password: null//密码
                }, req.params);
                if (!parm.Password || parm.Password == "") {
                    res.jsonp({flag: 1, msg: "密码错误，请重新输入密码"});
                    return;
                }
                if (!parm.Phone || parm.Phone == "") {
                    res.jsonp({flag: 1, msg: "电话号码错误，请重新输入密码"});
                    return;
                }
                DALFactory.Business.User_PasswordUpdate({
                    User_ID: null,
                    Phone: parm.Phone,
                    Password: parm.Password,
                    Password_Old: null,
                    Type: false //修改密码类型，true-验证旧密码,传User_ID，false-不验证旧密码,传Phone
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "修改密码成功"});
                });
            },
            //endregion
            //region CheckUserBindPhone  验证用户手机绑定
            CheckUserBindPhone: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "不登录不能进行此操作"});
                    return;
                }
                DALFactory.User.User_Info.Info(_UserData.User_ID, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    if (!retValue.returnObject) {
                        res.jsonp({flag: -1, msg: '没有此信息'});
                        return;
                    }
                    if (!retValue.returnObject.Phone) {
                        res.jsonp({flag: 0, msg: "验证失败", Phone: false});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "验证成功", Phone: true});
                });
            },
            //endregion
            //region CurrencyExchange:豆币兑换
            CurrencyExchange: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "不登录不能进行此操作"});
                    return;
                }
                DALFactory.Business.User_CurrencyExchange({
                    User_ID: _UserData.User_ID,//用户ID
                    Beans: req.params.Beans,//兑换的金豆数量
                    Create_IP: KOC.StringUtils.GetClientIP(req)//用户IP
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    res.jsonp({flag: 0, msg: "兑换成功"});
                });
            }
            //endregion
        },
        //endregion
        //region User_Task
        User_Task: {
            List: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "用户未登录"});
                    return;
                }
                var parm = KOC.Lodash.extend({
                    Mode: null,
                    Status: null
                }, req.params);
                parm.User_ID = _UserData.User_ID;
                DALFactory.User.User_Task.List(parm, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    //返回
                    res.jsonp({flag: 0, msg: "", data: retValue.returnObject});
                });
            },
            Update_Receive: function (req, res, _UserData) {
                if (!_UserData.IsLogin) {
                    res.jsonp({flag: -1, msg: "用户未登录"});
                    return;
                }
                var parm = KOC.Lodash.extend({
                    ID: null,
                    Mode: null,
                    Date: null
                }, req.params);
                DALFactory.Business.User_TaskReceive({
                    User_ID: _UserData.User_ID,
                    Task_ID: parm.ID,
                    Task_Mode: parm.Mode,
                    Task_Date: parm.Date,
                    Create_IP: KOC.StringUtils.GetClientIP(req)
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    //返回
                    res.jsonp({flag: 0, msg: "", data: retValue.returnObject});
                });
            }
        },
        //endregion
        //region User_Anchor
        User_Anchor: {
            Update: function (req, res, _UserData) {
                DALFactory.User.User_Anchor.Update({
                    RoomName: req.params.RoomName,
                    RoomWelcome: req.params.RoomWelcome,
                    RoomTemplate: req.params.RoomTemplate,
                    User_ID: _UserData.User_ID
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    if (retValue.returnObject !== 1) {
                        res.jsonp({flag: "", msg: "修改用户信息出错，影响行(" + retValue.returnObject + ")"});
                        return;
                    }
                    res.jsonp({flag: 0, msg: ""});
                });
            },
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                //查询参数
                var reqParm = new DALFactory.User.Page.UserAnchor_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "User_ID":
                            reqParm.User_ID = reqModel.Filter_Value;
                            break;
                        case "Phone":
                            reqParm.Phone = reqModel.Filter_Value;
                            break;
                        case "Email":
                            reqParm.Email = reqModel.Filter_Value;
                            break;
                        case "NickName":
                            reqParm.NickName = reqModel.Filter_Value;
                            break;
                        case "RoomName":
                            reqParm.RoomName = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.Sex = KOC.StringUtils.ToInt(req.params.Sex);
                reqParm.IsFamily = KOC.StringUtils.ToInt(req.params.IsFamily, -1);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID, -1);
                reqParm.User_ID = reqParm.User_ID ? reqParm.User_ID : KOC.StringUtils.ToInt(req.params.User_ID, -1);
                reqParm.NickName = reqParm.NickName ? reqParm.NickName : KOC.StringUtils.ToString(req.params.NickName, '');
                reqParm.RoomTitle = KOC.StringUtils.ToString(req.params.RoomTitle, '');
                reqParm.Live = KOC.StringUtils.ToInt(req.params.Live, -1);
                reqParm.Status = "0";
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "EXP":
                    case "Anchor_EXP":
                    case "Beans":
                    case "Beans_Today":
                    case "Beans_Week":
                    case "Beans_Month":
                    case "Beans_Year":
                    case "Beans_Total":
                    case "Fans":
                    case "Attention":
                    case "Login_This_Date":
                    case "Anchor_Pomelo":
                    case "Anchor_Pomelo_Today":
                    case "Anchor_Pomelo_Week":
                    case "Anchor_Pomelo_Month":
                    case "Anchor_Pomelo_Year":
                    case "HotValue":
                    case "Anchor_Status":
                    case "Family_ID":
                        break;
                    case "Create_Date":
                        reqModel.Sort_Col = "`User_ID`";
                        break;
                    case "Anchor_Create_Date":
                        reqModel.Sort_Col = "`Create_Date`";
                        break;
                    case "Anchor_Pomelo_Total":
                        reqModel.Sort_Col = "`Anchor_Pomelo`";
                        break;
                    default:
                        reqModel.Sort_Col = "`Live` DESC, `Live_Stream_Status` DESC, `HotValue` DESC, `Beans_Today` DESC";
                        reqModel.Sort_Dir = "";
                        break;
                }
                DALFactory.User.Page.UserAnchor(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            RoomName: ThisValue.RoomName,
                            RoomWelcome: ThisValue.RoomWelcome,
                            RoomTemplate: ThisValue.RoomTemplate,
                            RoomTitle: ThisValue.RoomTitle,
                            RoomNotice: ThisValue.RoomNotice,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Family_UserID: ThisValue.Family_UserID,
                            Sex: ThisValue.Sex,
                            EXP: ThisValue.EXP,
                            HotValue_Ranking: ThisValue.HotValue_Ranking,
                            HotValue: ThisValue.HotValue,
                            ActivityNum: ThisValue.ActivityNum,
                            Level: CommonUtils.User.Level.fnLevel(ThisValue.EXP),
                            Beans: ThisValue.Beans,
                            Beans_Today: ThisValue.Beans_Today,
                            Beans_Week: ThisValue.Beans_Week,
                            Beans_Month: ThisValue.Beans_Month,
                            Beans_Year: ThisValue.Beans_Year,
                            Beans_Total: ThisValue.Beans_Total,
                            Fans: ThisValue.Fans,
                            Attention: ThisValue.Attention,
                            IsFamily: ThisValue.IsFamily,
                            IsAnchor: ThisValue.IsAnchor,
                            Tags: ThisValue.Tags ? ThisValue.Tags.split(",") : null,
                            Live: ThisValue.Live,
                            Live_StartTime: ThisValue.Live_StartTime,
                            Live_Order_No: ThisValue.Live_Order_No,
                            Live_Duration_Total: ThisValue.Live_Duration_Total,
                            Live_IsMobile: ThisValue.Live_IsMobile,
                            Live_Mode: ThisValue.Live_Mode,
                            Live_Stream_LastDate: ThisValue.Live_Stream_LastDate,
                            Live_Stream_Status: ThisValue.Live_Stream_Status,
                            IsWeekStar: ThisValue.IsWeekStar,
                            IsRecommend: ThisValue.IsRecommend,
                            ProtectDue_Date: ThisValue.ProtectDue_Date,
                            Rating: ThisValue.Rating,
                            Score: ThisValue.Score,
                            Integral: ThisValue.Integral,
                            Integral_Month: ThisValue.Integral_Month,
                            Integral_Month_Last: ThisValue.Integral_Month_Last,
                            Integral_Week: ThisValue.Integral_Week,
                            Integral_Week_Last: ThisValue.Integral_Week_Last,
                            Integral_Date: ThisValue.Integral_Date,
                            Anchor_Pomelo: ThisValue.Anchor_Pomelo,
                            Anchor_Pomelo_Today: ThisValue.Anchor_Pomelo_Today,
                            Anchor_Pomelo_Week: ThisValue.Anchor_Pomelo_Week,
                            Anchor_Pomelo_Month: ThisValue.Anchor_Pomelo_Month,
                            Anchor_Pomelo_Year: ThisValue.Anchor_Pomelo_Year,
                            Anchor_EXP: ThisValue.Anchor_EXP,
                            Anchor_Level: CommonUtils.Anchor.Level.fnLevel(ThisValue.Anchor_EXP).Level,
                            ApplyMoney_LastDate: ThisValue.ApplyMoney_LastDate,
                            Create_Date: ThisValue.Create_Date,
                            Anchor_Create_Date: ThisValue.Create_Date,
                            Status: ThisValue.Status,
                            Anchor_Status: ThisValue.Status
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region User_Anchor_Guardian
        User_Anchor_Guardian: {
            List_Guardian: function (req, res, _UserData) {
                DALFactory.User.User_Anchor_Guardian.List_Guardian(req.params.User_ID, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    //返回
                    res.jsonp({flag: 0, msg: "", data: retValue.returnObject});
                });
            }
        },
        //endregion
        //region User_Contribution
        User_Contribution: {
            List: function (req, res, _UserData) {
                DALFactory.User.User_Contribution.List({
                    TopN: req.params.TopN,
                    User_ID_Contribution: req.params.User_ID,
                    OrderBy: req.params.OrderBy
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        ThisValue.Level = CommonUtils.User.Level.fnLevel(ThisValue.EXP).Level;
                    });
                    //返回
                    res.jsonp({flag: 0, msg: "", data: retValue.returnObject});
                });
            }
        },
        //endregion
        //region User_Attention
        User_Attention: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.UserAttention_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Phone":
                            reqParm.Phone = reqModel.Filter_Value;
                            break;
                        case "Email":
                            reqParm.Email = reqModel.Filter_Value;
                            break;
                        case "NickName":
                            reqParm.NickName = reqModel.Filter_Value;
                            break;
                        case "RoomName":
                            reqParm.RoomName = reqModel.Filter_Value;
                            break;
                        case "Tags":
                            reqParm.Tags = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = _UserData.User_ID;
                reqParm.Sex = KOC.StringUtils.ToInt(req.params.F_Sex);
                reqParm.IsFamily = KOC.StringUtils.ToInt(req.params.F_IsFamily, -1);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.F_Family_ID, -1);
                reqParm.Live = KOC.StringUtils.ToInt(req.params.F_Live);
                reqParm.Status = req.params.F_Status || reqParm.Status;
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "EXP":
                    case "VIP":
                    case "VIP_Expire":
                    case "Beans":
                    case "Fans":
                    case "Attention":
                    case "Login_Count":
                    case "Login_This_Date":
                        break;
                    case "User_Create_Date":
                        reqModel.Sort_Col = "`User_ID`";
                        break;
                    case "Live":
                    case "Live_StartTime":
                    case "Live_Order_No":
                    case "Live_Duration_Total":
                    case "Anchor_Pomelo":
                    case "Anchor_EXP":
                    case "Anchor_Create_Date":
                        break;
                    case "Family_ID":
                        break;
                    default:
                        reqModel.Sort_Col = "`Create_Date`";
                        break;
                }
                DALFactory.User.Page.UserAttention(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Create_Date: ThisValue.Create_Date,
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            QQ: ThisValue.QQ,
                            Sex: ThisValue.Sex,
                            Birthday: ThisValue.Birthday,
                            Constellation: ThisValue.Constellation,
                            EXP: ThisValue.EXP,
                            Level: CommonUtils.User.Level.fnLevel(ThisValue.EXP),
                            VIP: ThisValue.VIP && (!ThisValue.VIP_Expire || KOC.Moment().isBefore(retValue.returnObject.VIP_Expire)),
                            VIP_Expire: ThisValue.VIP_Expire,
                            Beans: ThisValue.Beans,
                            Fans: ThisValue.Fans,
                            Attention: ThisValue.Attention,
                            IsAnchor: ThisValue.IsAnchor,
                            IsFamily: ThisValue.IsFamily,
                            Login_Count: ThisValue.Login_Count,
                            Login_This_Date: ThisValue.Login_This_Date,
                            User_Create_Date: ThisValue.User_Create_Date,
                            RoomName: ThisValue.RoomName,
                            RoomWelcome: ThisValue.RoomWelcome,
                            Tags: ThisValue.Tags,
                            Live: ThisValue.Live,
                            Live_StartTime: ThisValue.Live_StartTime,
                            Live_Order_No: ThisValue.Live_Order_No,
                            Live_Duration_Total: ThisValue.Live_Duration_Total,
                            Live_IsMobile: ThisValue.Live_IsMobile,
                            Anchor_Pomelo: ThisValue.Anchor_Pomelo,
                            Anchor_EXP: ThisValue.Anchor_EXP,
                            Anchor_Level: CommonUtils.Anchor.Level.fnLevel(ThisValue.Anchor_EXP).Level,
                            Anchor_HotValue: ThisValue.Anchor_HotValue,
                            Anchor_Create_Date: ThisValue.Anchor_Create_Date,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Family_Create_Date: ThisValue.Family_Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            },
            AnchorFans: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.UserAnchorFans_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Phone":
                            reqParm.Phone = reqModel.Filter_Value;
                            break;
                        case "Email":
                            reqParm.Email = reqModel.Filter_Value;
                            break;
                        case "NickName":
                            reqParm.NickName = reqModel.Filter_Value;
                            break;
                        case "RoomName":
                            reqParm.RoomName = reqModel.Filter_Value;
                            break;
                        case "Tags":
                            reqParm.Tags = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID_Attention = _UserData.User_ID;
                reqParm.Sex = KOC.StringUtils.ToInt(req.params.F_Sex);
                reqParm.IsFamily = KOC.StringUtils.ToInt(req.params.F_IsFamily, -1);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.F_Family_ID, -1);
                reqParm.Live = KOC.StringUtils.ToInt(req.params.F_Live);
                reqParm.Status = req.params.F_Status || reqParm.Status;
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "EXP":
                    case "VIP":
                    case "Coin":
                    case "VIP_Expire":
                    case "Beans":
                    case "Fans":
                    case "Attention":
                    case "Login_Count":
                    case "Login_This_Date":
                        break;
                    case "User_Create_Date":
                        reqModel.Sort_Col = "`User_ID`";
                        break;
                    case "Live":
                    case "Live_StartTime":
                    case "Live_Order_No":
                    case "Live_Duration_Total":
                    case "Anchor_Pomelo":
                    case "Anchor_EXP":
                    case "Anchor_Create_Date":
                        break;
                    case "Family_ID":
                        break;
                    default:
                        reqModel.Sort_Col = "`Create_Date`";
                        break;
                }
                DALFactory.User.Page.UserAnchorFans(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Create_Date: ThisValue.Create_Date,
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            QQ: ThisValue.QQ,
                            Sex: ThisValue.Sex,
                            Birthday: ThisValue.Birthday,
                            Constellation: ThisValue.Constellation,
                            EXP: ThisValue.EXP,
                            Level: CommonUtils.User.Level.fnLevel(ThisValue.EXP),
                            VIP: ThisValue.VIP && (!ThisValue.VIP_Expire || KOC.Moment().isBefore(retValue.returnObject.VIP_Expire)),
                            VIP_Expire: ThisValue.VIP_Expire,
                            Beans: ThisValue.Beans,
                            Fans: ThisValue.Fans,
                            Attention: ThisValue.Attention,
                            IsAnchor: ThisValue.IsAnchor,
                            IsFamily: ThisValue.IsFamily,
                            Login_Count: ThisValue.Login_Count,
                            Login_This_Date: ThisValue.Login_This_Date,
                            User_Create_Date: ThisValue.User_Create_Date,
                            Coin: ThisValue.Coin ? ThisValue.Coin : 0,
                            Coin_Live: ThisValue.Coin_Live ? ThisValue.Coin_Live : 0,
                            Coin_Day: ThisValue.Coin_Day ? ThisValue.Coin_Day : 0,
                            Coin_Week: ThisValue.Coin_Week ? ThisValue.Coin_Week : 0,
                            Coin_Month: ThisValue.Coin_Month ? ThisValue.Coin_Month : 0,
                            Coin_Year: ThisValue.Coin_Year ? ThisValue.Coin_Year : 0,
                            RoomName: ThisValue.RoomName,
                            RoomWelcome: ThisValue.RoomWelcome,
                            Tags: ThisValue.Tags,
                            Live: ThisValue.Live,
                            Live_StartTime: ThisValue.Live_StartTime,
                            Live_Order_No: ThisValue.Live_Order_No,
                            Live_Duration_Total: ThisValue.Live_Duration_Total,
                            Live_IsMobile: ThisValue.Live_IsMobile,
                            Anchor_Pomelo: ThisValue.Anchor_Pomelo,
                            Anchor_EXP: ThisValue.Anchor_EXP,
                            Anchor_Level: CommonUtils.Anchor.Level.fnLevel(ThisValue.Anchor_EXP).Level,
                            Anchor_HotValue: ThisValue.Anchor_HotValue,
                            Anchor_Create_Date: ThisValue.Anchor_Create_Date,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Family_Create_Date: ThisValue.Family_Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region Order_Gift：礼物列表
        Order_Gift: {
            //用户送出的礼物
            PageUser: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (req.params.Create_Date && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Create_Date)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderGiftOld_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Live_Order_No":
                            //直播单据号
                            reqParm.Live_Order_No = reqModel.Filter_Value;
                            break;
                        case "User_NickName":
                            //用户昵称(送出人)
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "User_NickName_Gift":
                            //用户昵称(接收人)
                            reqParm.User_NickName_Gift = reqModel.Filter_Value;
                            break;
                        case "Family_Name":
                            //公会名(接收人)
                            reqParm.Family_Name = reqModel.Filter_Value;
                            break;
                        case "Gift_Name":
                            //礼物商品名称
                            reqParm.Gift_Name = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = KOC.StringUtils.ToInt(req.params.User_ID);
                reqParm.User_ID_Anchor = KOC.StringUtils.ToInt(req.params.User_ID_Anchor);
                reqParm.User_ID_Gift = KOC.StringUtils.ToInt(req.params.User_ID_Gift);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID);
                reqParm.Gift_ID = KOC.StringUtils.ToInt(req.params.Gift_ID);
                reqParm.Gift_ID = KOC.StringUtils.ToInt(req.params.Gift_ID);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                //传入Create_Date为字符串“2016-01”，查询一个月内的数据，特殊处理
                if (req.params.Create_Date) {
                    reqParm.Create_Date_Between = KOC.Moment(req.params.Create_Date)._d;
                    reqParm.Create_Date_And = KOC.Moment(req.params.Create_Date).add(1, 'M')._d;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "Live_Order_No":
                    case "User_ID_Anchor":
                    case "User_NickName":
                    case "User_ID_Gift":
                    case "User_NickName_Gift":
                    case "Family_ID":
                    case "Family_Name":
                    case "Gift_ID":
                    case "Gift_Name":
                    case "Create_Date":
                    case "User_ID":
                        break;
                }
                DALFactory.User.Page.OrderGiftOld(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            Live_Order_No: ThisValue.Live_Order_No,
                            User_ID_Anchor: ThisValue.User_ID_Anchor,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            User_ID_Gift: ThisValue.User_ID_Gift,
                            User_NickName_Gift: ThisValue.User_NickName_Gift,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Gift_ID: ThisValue.Gift_ID,
                            Gift_Name: ThisValue.Gift_Name,
                            Gift_Price: ThisValue.Gift_Price,
                            Order_Num: ThisValue.Order_Num,
                            Commission_Gift_Family: ThisValue.Commission_Gift_Family,
                            Commission_Gift_Anchor: ThisValue.Commission_Gift_Anchor,
                            Commission_Anchor_Family: ThisValue.Commission_Anchor_Family,
                            Order_Amt_Anchor: ThisValue.Order_Amt_Anchor,
                            Order_Amt_Platform: ThisValue.Order_Amt_Platform,
                            Order_Amt_Family: ThisValue.Order_Amt_Family,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            },
            //艺人收到的礼物
            PageAnchor: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (_UserData.IsAnchor != 1) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("你不是艺人", reqModel.Echo));
                    return;
                }
                if (req.params.Create_Date && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Create_Date)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderGiftOld_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Live_Order_No":
                            //直播单据号
                            reqParm.Live_Order_No = reqModel.Filter_Value;
                            break;
                        case "User_NickName":
                            //用户昵称(送出人)
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "User_NickName_Gift":
                            //用户昵称(接收人)
                            reqParm.User_NickName_Gift = reqModel.Filter_Value;
                            break;
                        case "Family_Name":
                            //公会名(接收人)
                            reqParm.Family_Name = reqModel.Filter_Value;
                            break;
                        case "Gift_Name":
                            //礼物商品名称
                            reqParm.Gift_Name = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = KOC.StringUtils.ToInt(req.params.User_ID);
                reqParm.User_ID_Anchor = KOC.StringUtils.ToInt(_UserData.User_ID);
                reqParm.User_ID_Gift = KOC.StringUtils.ToInt(req.params.User_ID_Gift);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID);
                reqParm.Gift_ID = KOC.StringUtils.ToInt(req.params.Gift_ID);
                reqParm.Gift_ID = KOC.StringUtils.ToInt(req.params.Gift_ID);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                //传入Create_Date为字符串“2016-01”，查询一个月内的数据，特殊处理
                if (req.params.Create_Date) {
                    reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date)._d : null;
                    reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(1, 'M')._d : null;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "Live_Order_No":
                    case "User_ID_Anchor":
                    case "User_NickName":
                    case "User_ID_Gift":
                    case "User_NickName_Gift":
                    case "Family_ID":
                    case "Family_Name":
                    case "Gift_ID":
                    case "Gift_Name":
                    case "Create_Date":
                    case "User_ID":
                        break;
                }
                DALFactory.User.Page.OrderGiftOld(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            Live_Order_No: ThisValue.Live_Order_No,
                            User_ID_Anchor: ThisValue.User_ID_Anchor,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            User_ID_Gift: ThisValue.User_ID_Gift,
                            User_NickName_Gift: ThisValue.User_NickName_Gift,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            Gift_ID: ThisValue.Gift_ID,
                            Gift_Name: ThisValue.Gift_Name,
                            Gift_Price: ThisValue.Gift_Price,
                            Order_Num: ThisValue.Order_Num,
                            Commission_Gift_Family: ThisValue.Commission_Gift_Family,
                            Commission_Gift_Anchor: ThisValue.Commission_Gift_Anchor,
                            Commission_Anchor_Family: ThisValue.Commission_Anchor_Family,
                            Order_Amt_Anchor: ThisValue.Order_Amt_Anchor,
                            Order_Amt_Platform: ThisValue.Order_Amt_Platform,
                            Order_Amt_Family: ThisValue.Order_Amt_Family,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            },
        },
        //endregion
        //region Order_Guardian：守护列表
        Order_Guardian: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderGuardianOld_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Live_Order_No":
                            //直播单据号
                            reqParm.Live_Order_No = reqModel.Filter_Value;
                            break;
                        case "User_NickName":
                            //用户名称(守护人)
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "Guardian_Name":
                            //守户商品名称
                            reqParm.Guardian_Name = reqModel.Filter_Value;
                            break;
                        case "Family_Name":
                            //公会名(被守护人)
                            reqParm.Family_Name = reqModel.Filter_Value;
                            break;
                        case "User_NickName_Guardian":
                            //用户名称(被守护人)
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "Guardian_Mode":
                            //守户模式：YEAR, MONTY, WEEK, DAY
                            reqParm.Guardian_Mode = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = _UserData.User_ID;
                reqParm.User_ID_Guardian = KOC.StringUtils.ToInt(req.params.User_ID_Guardian);
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID);
                reqParm.Guardian_ID = KOC.StringUtils.ToInt(req.params.Guardian_ID);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                //排序
                switch (reqModel.Sort_Col) {
                    case "Live_Order_No":
                    case "User_ID_Guardian":
                    case "Family_ID":
                    case "User_ID":
                    case "Guardian_ID":
                    case "Create_Date":
                    case "Guardian_Name":
                    case "Family_Name":
                    case "User_NickName_Guardian":
                    case "Guardian_Mode":
                        break;
                }
                DALFactory.User.Page.OrderGuardianOld(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            Live_Order_No: ThisValue.Live_Order_No,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            User_ID_Guardian: ThisValue.User_ID_Guardian,
                            User_NickName_Guardian: ThisValue.User_NickName_Guardian,
                            Family_Name: ThisValue.Family_Name,
                            Family_ID: ThisValue.Family_ID,
                            Guardian_ID: ThisValue.Guardian_ID,
                            Guardian_Name: ThisValue.Guardian_Name,
                            Guardian_Mode: ThisValue.Guardian_Mode,
                            Guardian_Value: ThisValue.Guardian_Value,
                            Order_Amt: ThisValue.Order_Amt,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region Order_Vip：VIP列表
        Order_Vip: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderVip_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "User_NickName":
                            //用户名称
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "VIP_Mode":
                            //VIP模式：YEAR, MONTY, WEEK, DAY
                            reqParm.VIP_Mode = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = _UserData.User_ID;
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                //排序
                switch (reqModel.Sort_Col) {
                    case "Create_Date":
                    case "User_ID":
                    case "VIP_Mode":
                    case "User_NickName":
                        break;
                }
                DALFactory.User.Page.OrderVip(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            VIP_ID: ThisValue.VIP_ID,
                            VIP_Name: ThisValue.VIP_Name,
                            VIP_Value: ThisValue.VIP_Value,
                            VIP_Mode: ThisValue.VIP_Mode,
                            Order_Amt: ThisValue.Order_Amt,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region Order_Mounts：坐骑列表
        Order_Mounts: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderMountsOld_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "User_NickName":
                            //用户名称
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "Mounts_Name":
                            //坐骑商品名称
                            reqParm.Mounts_Name = reqModel.Filter_Value;
                            break;
                        case "Mounts_Mode":
                            //坐骑模式：YEAR, MONTY, WEEK, DAY
                            reqParm.Mounts_Mode = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = _UserData.User_ID;
                reqParm.Mounts_ID = KOC.StringUtils.ToInt(req.params.Mounts_ID);
                reqParm.Mounts_Price = KOC.StringUtils.ToInt(req.params.Mounts_Price);
                reqParm.Order_Num = KOC.StringUtils.ToInt(req.params.Order_Num);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "User_NickName":
                    case "Mounts_ID":
                    case "Mounts_Name":
                    case "Mounts_Price":
                    case "Mounts_Mode":
                    case "Order_Num":
                    case "Create_Date":
                        break;
                }
                DALFactory.User.Page.OrderMountsOld(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            Mounts_ID: ThisValue.Mounts_ID,
                            Mounts_Name: ThisValue.Mounts_Name,
                            Mounts_Mode: ThisValue.Mounts_Mode,
                            Mounts_Value: ThisValue.Mounts_Value,
                            Mounts_Price: ThisValue.Mounts_Price,
                            Order_Num: ThisValue.Order_Num,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region Order_Live：直播数据列表
        Order_Live: {
            //用户的直播列表
            PageUser: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (_UserData.IsAnchor != 1 && _UserData.IsFamily != 1) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("你不是艺人", reqModel.Echo));
                    return;
                }
                if (req.params.Report_Day && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Report_Day)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.Report.Page.AnchorDayStatistics_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "NickName":
                            //用户名称
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "Family_Name":
                            //公会名称
                            reqParm.Family_Name = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = req.params.User_ID;
                if (!reqParm.User_ID) {
                    reqParm.User_ID = _UserData.User_ID;
                }
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID);
                //传入Create_Date为字符串“2016-01”，查询一个月内的数据，特殊处理
                if (req.params.Report_Day) {
                    reqParm.Create_Date_Between = req.params.Report_Day ? KOC.Moment(KOC.Moment(req.params.Report_Day)._d).format('YYYY-MM-DD') : null;
                    reqParm.Create_Date_And = req.params.Report_Day ? KOC.Moment(KOC.Moment(req.params.Report_Day).add(1, 'M')._d).format('YYYY-MM-DD') : null;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "Report_Day":
                    case "User_ID":
                    case "Family_ID":
                    case "Coin":
                    case "NickName":
                    case "Family_Name":
                        break;
                }
                DALFactory.Report.Page.AnchorDayStatistics(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Report_Day: ThisValue.Report_Day ? KOC.Moment(ThisValue.Report_Day).format('YYYY-MM-DD') : '0000-00-00',
                            User_ID: ThisValue.User_ID,
                            Family_ID: ThisValue.Family_ID,
                            Family_Name: ThisValue.Family_Name,
                            NickName: ThisValue.NickName,
                            RealName: ThisValue.RealName,
                            Coin: ThisValue.Coin,
                            Beans_Anchor: ThisValue.Beans_Anchor,
                            Beans_Family: ThisValue.Beans_Family,
                            Beans_Platform: ThisValue.Beans_Platform,
                            Live_Count: ThisValue.Live_Count,
                            Live_Duration: ThisValue.Live_Duration,
                            Live_Duration_Efftive: ThisValue.Live_Duration_Efftive,
                            Gift_Count: ThisValue.Gift_Count,
                            Gift_Num: ThisValue.Gift_Num,
                            Gift_Coin: ThisValue.Gift_Coin,
                            Gift_Beans_Anchor: ThisValue.Gift_Beans_Anchor,
                            Gift_Beans_Family: ThisValue.Gift_Beans_Family,
                            Gift_Beans_Platform: ThisValue.Gift_Beans_Platform,
                            Gift_Pond_Count: ThisValue.Gift_Pond_Count,
                            Gift_Pond_Coin: ThisValue.Gift_Pond_Coin,
                            Guardian_Count: ThisValue.Guardian_Count,
                            Guardian_Coin: ThisValue.Guardian_Coin,
                            Guardian_Beans_Anchor: ThisValue.Guardian_Beans_Anchor,
                            Guardian_Beans_Family: ThisValue.Guardian_Beans_Family,
                            Guardian_Beans_Platform: ThisValue.Guardian_Beans_Platform,
                            Horn_Count: ThisValue.Horn_Count,
                            Horn_Coin: ThisValue.Horn_Coin,
                            Horn_Beans_Anchor: ThisValue.Horn_Beans_Anchor,
                            Horn_Beans_Family: ThisValue.Horn_Beans_Family,
                            Horn_Beans_Platform: ThisValue.Horn_Beans_Platform,
                            User_SignUp_Count: ThisValue.User_SignUp_Count
                        });
                    });
                    res.jsonp(PageData);
                });
            },
            //公会的直播列表
            PageFamily: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (_UserData.IsFamily != 1 || !_UserData.IsFamily) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("你没有公会", reqModel.Echo));
                    return;
                }
                if (!req.params.Family_ID || req.params.Family_ID == -1) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("公会ID不存在", reqModel.Echo));
                    return;
                }
                if (req.params.Report_Day && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Report_Day)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.Report.Page.FamilyAnchorMonthStatistics_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Family_Name":
                            //公会名称
                            reqParm.Family_Name = reqModel.Filter_Value;
                            break;
                            //公会名称
                            reqParm.NickName = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = KOC.StringUtils.ToInt(req.params.User_ID) ? KOC.StringUtils.ToInt(req.params.User_ID) : null;
                reqParm.Family_ID = KOC.StringUtils.ToInt(req.params.Family_ID) ? KOC.StringUtils.ToInt(req.params.Family_ID) : null;
                reqParm.NickName = req.params.NickName ? req.params.NickName : null;
                //传入Create_Date为字符串“2016-01”，查询一个月内的数据，特殊处理
                if (req.params.Report_Day) {
                    reqParm.Create_Date_Between = req.params.Report_Day ? KOC.Moment(KOC.Moment(req.params.Report_Day)._d).format('YYYY-MM-DD') : null;
                    reqParm.Create_Date_And = req.params.Report_Day ? KOC.Moment(KOC.Moment(req.params.Report_Day).add(1, 'M')._d).format('YYYY-MM-DD') : null;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "Family_ID":
                    case "Report_Day":
                        break;
                }
                DALFactory.Report.Page.FamilyAnchorMonthStatistics(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Report_Day: ThisValue.Report_Day,
                            Month: ThisValue.Month,
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            Family_ID: ThisValue.Family_ID,
                            Sum_LiveDuring: ThisValue.Sum_LiveDuring,
                            Sum_LiveDuring_Efftive: ThisValue.Sum_LiveDuring_Efftive,
                            Sum_BeansAnchor: ThisValue.Sum_BeansAnchor,
                            Sum_Efftive: ThisValue.Sum_Efftive
                        });
                    });
                    res.jsonp(PageData);
                });
            }
        },
        //endregion
        //region Order_Pay：交易记录列表
        Order_Pay: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (req.params.Create_Date && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Create_Date)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderPay_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "User_NickName":
                            //用户名称
                            reqParm.User_NickName = reqModel.Filter_Value;
                            break;
                        case "Pay_TransNumber":
                            //支付返回的交易号
                            reqParm.Pay_TransNumber = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = _UserData.User_ID;
                reqParm.User_NickName = KOC.StringUtils.ToInt(req.params.User_NickName);
                reqParm.Pay_Type = KOC.StringUtils.ToInt(req.params.Pay_Type);
                reqParm.Pay_Money_Between = KOC.StringUtils.ToInt(req.params.Pay_Money_Between);
                reqParm.Pay_Money_And = KOC.StringUtils.ToInt(req.params.Pay_Money_And);
                reqParm.Pay_TransNumber = KOC.StringUtils.ToInt(req.params.Pay_TransNumber);
                reqParm.Update_Date_Between = KOC.StringUtils.ToInt(req.params.Update_Date_Between);
                reqParm.Update_Date_And = KOC.StringUtils.ToInt(req.params.Update_Date_And);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                reqParm.Status = req.params.Status ? KOC.StringUtils.ToInt(req.params.Status) : 0;
                //传入Create_Date为字符串“2016-01”，查询一个月内的数据，特殊处理
                if (req.params.Create_Date && req.params.Create_Date != "") {
                    reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date)._d : null;
                    reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(1, 'M')._d : null;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "User_NickName":
                    case "Pay_Type":
                    case "Pay_Money":
                    case "Update_Date":
                    case "Create_Date":
                        break;
                }
                DALFactory.User.Page.OrderPay(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            Pay_Type: ThisValue.Pay_Type,
                            Pay_Money: ThisValue.Pay_Money,
                            Pay_Style: ThisValue.Pay_Style,
                            Pay_From: ThisValue.Pay_From,
                            Pay_Coin: ThisValue.Pay_Coin,
                            Pay_Poundage: ThisValue.Pay_Poundage,
                            Pay_TransNumber: ThisValue.Pay_TransNumber,
                            Update_Date: ThisValue.Update_Date,
                            Create_Date: ThisValue.Create_Date,
                            Create_IP: ThisValue.Create_IP,
                            Status: ThisValue.Status
                        });
                    });
                    res.jsonp(PageData);
                });
            },
        },
        //endregion
        //region Order_Withdraw：申请提现用户列表
        Order_Withdraw: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (!_UserData.IsLogin) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("请登录后使用此功能", reqModel.Echo));
                    return;
                }
                if (req.params.Create_Date && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Create_Date)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.OrderWithdraw_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Order_No":
                            //单据号
                            reqParm.Order_No = reqModel.Filter_Value;
                            break;
                        case "User_ID":
                            //单据号
                            reqParm.User_ID = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.User_ID = req.params.User_ID ? KOC.StringUtils.ToInt(req.params.User_ID) : _UserData.User_ID;
                reqParm.Order_No = req.params.Order_No ? req.params.Order_No : null;
                reqParm.Account_BankName = req.params.Account_BankName ? req.params.Account_BankName : null;
                reqParm.Account_BankFullName = req.params.Account_BankFullName ? req.params.Account_BankFullName : null;
                reqParm.Account_RealName = req.params.Account_RealName ? req.params.Account_RealName : null;
                reqParm.Account_CardNo = req.params.Account_CardNo ? req.params.Account_CardNo : null;
                reqParm.IDCard = req.params.IDCard ? req.params.IDCard : null;
                reqParm.Update_Date_Between = KOC.StringUtils.ToInt(req.params.Update_Date_Between);
                reqParm.Update_Date_And = KOC.StringUtils.ToInt(req.params.Update_Date_And);
                reqParm.Create_Date_Between = KOC.StringUtils.ToInt(req.params.Create_Date_Between);
                reqParm.Create_Date_And = KOC.StringUtils.ToInt(req.params.Create_Date_And);
                reqParm.Status = req.params.Status == '0' || req.params.Status == '1' ? KOC.StringUtils.ToInt(req.params.Status) : null;
                //按月份的上中下旬查询，传入2016-06
                if (req.params.Create_Date && req.params.Create_Date != "" && req.params.Type) {
                    switch (req.params.Type) {
                        case "上旬":
                            reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date)._d : null;
                            reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(10, 'd')._d : null;
                            break;
                        case "中旬":
                            reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(10, 'd')._d : null;
                            reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(20, 'd')._d : null;
                            break;
                        case "下旬":
                            reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(20, 'd')._d : null;
                            reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(1, 'M')._d : null;
                            break;
                        default:
                            res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("传入类型错误：Type" + req.params.Type));
                            return;
                            break;
                    }
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "Order_No":
                    case "Update_Date":
                    case "Create_Date":
                        break;
                }
                DALFactory.User.Page.OrderWithdraw(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            RealName: ThisValue.RealName,
                            Email: ThisValue.Email,
                            Phone: ThisValue.Phone,
                            QQ: ThisValue.QQ,
                            Sex: ThisValue.Sex,
                            Money: ThisValue.Money,
                            Revenue_Money: ThisValue.Revenue_Money,
                            Real_Money: ThisValue.Real_Money,
                            Update_Date: ThisValue.Update_Date,
                            Create_Date: ThisValue.Create_Date,
                            Status: ThisValue.Status,
                            Network: ThisValue.Network,
                            Account_BankName: ThisValue.Account_BankName,
                            Account_BankFullName: ThisValue.Account_BankFullName,
                            Account_RealName: ThisValue.Account_RealName,
                            Account_CardNo: ThisValue.Account_CardNo,
                            IDCard: ThisValue.IDCard,
                            Family_ID: ThisValue.Family_ID,
                            Anchor_Status: ThisValue.Anchor_Status
                        });
                    });
                    res.jsonp(PageData);
                });
            },
        },
        //endregion
        //region Order_Lottery：抽奖中奖列表
        Order_Lottery: {
            Page: function (req, res, _UserData) {
                var reqModel = CommonUtils.Common.AjaxPage.Request(req);
                if (req.params.Create_Date && !(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(req.params.Create_Date)) {
                    res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode("时间格式错误"));
                    return;
                }
                //查询参数
                var reqParm = new DALFactory.User.Page.Order_Lottery_Parm();
                if (reqModel.Filter_Value.length > 0) {
                    switch (reqModel.Filter_Type) {
                        case "Order_No":
                            //单据号
                            reqParm.Order_No = reqModel.Filter_Value;
                            break;
                        case "User_ID":
                            //单据号
                            reqParm.User_ID = reqModel.Filter_Value;
                            break;
                        default:
                            reqParm.FuzzyQuery = reqModel.Filter_Value;
                            break;
                    }
                }
                reqParm.Order_No = req.params.Order_No ? req.params.Order_No : null;
                reqParm.IsWinning = "true";//只返回已中奖的
                //按月份
                if (req.params.Create_Date && req.params.Create_Date != "") {
                    reqParm.Create_Date_Between = req.params.Create_Date ? KOC.Moment(req.params.Create_Date)._d : null;
                    reqParm.Create_Date_And = req.params.Create_Date ? KOC.Moment(req.params.Create_Date).add(1, 'M')._d : null;
                }
                //排序
                switch (reqModel.Sort_Col) {
                    case "User_ID":
                    case "Order_No":
                    case "Create_Date":
                        break;
                }
                DALFactory.User.Page.Order_Lottery(reqParm, reqModel, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp(CommonUtils.Common.AjaxPage.ErrorCode(retValue.message + "(" + retValue.errorCode + ")", reqModel.Echo));
                        return;
                    }
                    var PageData = CommonUtils.Common.AjaxPage.PageData(reqModel, retValue);
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        PageData.aaData.push({
                            Order_No: ThisValue.Order_No,
                            User_ID: ThisValue.User_ID,
                            User_NickName: ThisValue.User_NickName,
                            User_RealName: ThisValue.User_RealName,
                            User_ID_Anchor: ThisValue.User_ID_Anchor,
                            Order_Amt: ThisValue.Order_Amt,
                            Lottery_Num: ThisValue.Lottery_Num,
                            IsWinning: ThisValue.IsWinning,
                            Winning_Type: ThisValue.Winning_Type,
                            Winning_ID: ThisValue.Winning_ID,
                            Winning_Mode: ThisValue.Winning_Mode,
                            Winning_Value: ThisValue.Winning_Amt_Virtual,
                            Winning_Amt: ThisValue.Winning_Amt,
                            Winning_Amt_Virtual: ThisValue.Winning_Amt_Virtual,
                            Winning_Text: ThisValue.Winning_Text,
                            Create_Date: ThisValue.Create_Date
                        });
                    });
                    res.jsonp(PageData);
                });
            },
            LotteryRank: function (req, res, _UserData) {
                var parm = KOC.Lodash.extend({
                    Length: null,//获取个数
                    Type: null,//获取榜单类型：1-日榜，2-周榜，3-月榜，4-年榜，5=总榜，6-任意时间段榜单
                    BetweenTime: null,//开始时间
                    AndTime: null//结束时间
                }, req.params);
                DALFactory.Business.User_LotteryRank({
                    Length: parm.Length,//获取个数
                    Type: parm.Type,//获取榜单类型：1-日榜，2-周榜，3-月榜，4-年榜，5=总榜，6-任意时间段榜单
                    BetweenTime: parm.BetweenTime,//开始时间
                    AndTime: parm.AndTime//结束时间
                }, function (retValue) {
                    if (retValue.hasError) {
                        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
                        return;
                    }
                    var data = [];
                    KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
                        data.push({
                            User_ID: ThisValue.User_ID,
                            NickName: ThisValue.NickName,
                            SUM_WinningValue: ThisValue.SUM_Winning_Value//奖励总价值
                        });
                    });
                    //返回
                    res.jsonp({flag: 0, msg: "获取抽奖榜单成功" + parm.Type, data: data});
                });
            }
        }
        //endregion
    }
};